package net.minecraft.src;
// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) braces deadcode 

import java.lang.reflect.Method;
import net.minecraft.client.Minecraft;
import org.lwjgl.input.Keyboard;

public class mod_MovePlus extends BaseMod
    implements Runnable
{
	
	public static int spriteIndex;
    public static String modName = "MovePlus";
    public static World worldRef;
    public static EntityPlayer theplayer;
    public static Minecraft mc;
    public static int timeout;
    public static String msg;
    public static int color;
    public static int defaultColor = 0xffffff;
    public static int lastKey = 0;
    public static int keys[];
    public static long keyTimes[] = {
        0L, 0L, 0L, 0L, 0L
    };
    public static boolean secondPress[] = {
        false, false, false, false, false
    };
    public static boolean dodged;
    public static boolean doubleJumped;
    public static int minDelayTime = 7;
    public static long tickCount = 0L;
    public static long timeCount = 0L;
    public static long prevTimeCount = 0L;
    
    public static boolean useDoubleJump = true;
    public static boolean useGroundDodge = true;
    public static boolean useWallDodge = true;
    public static boolean useAirDodge = true;
    public static boolean useBoostDodge = true;
    public static boolean useDoubleDodge = true;

    public void run()
    {
        try
        {
            while(true) 
            {
                mod_MovePlus _tmp = this;
                if(mc == null)
                {
                    mod_MovePlus _tmp1 = this;
                    mc = ModLoader.getMinecraftInstance();
                }
                mod_MovePlus _tmp2 = this;
                if(mc == null)
                {
                    Thread.sleep(5000L);
                } else
                {
                    mod_MovePlus _tmp3 = this;
                    if(mc.thePlayer == null)
                    {
                        Thread.sleep(5000L);
                    } else
                    {
                        mod_MovePlus _tmp4 = this;
                        worldRef = mc.theWorld;
                        mod_MovePlus _tmp5 = this;
                        theplayer = mc.thePlayer;
                        keys = (new int[] {
                            mc.gameSettings.keyBindForward.keyCode, mc.gameSettings.keyBindLeft.keyCode, mc.gameSettings.keyBindBack.keyCode, mc.gameSettings.keyBindRight.keyCode, mc.gameSettings.keyBindJump.keyCode
                        });
                        Thread.sleep(10000L);
                    }
                }
            }
        }
        catch(Throwable throwable)
        {
            throwable.printStackTrace();
        }
    }

    public mod_MovePlus()
    {
        /*try
        {
            Method method = (ModLoader.class).getDeclaredMethod("SetInGameHook", new Class[] {
                BaseMod.class, Boolean.TYPE, Boolean.TYPE
            });
            method.invoke(null, new Object[] {
                this, Boolean.valueOf(true), Boolean.valueOf(false)
            });
        }
        catch(Throwable throwable) { }*/
    	
    	ModLoader.SetInGameHook(this,true,false);
    	ModLoader.SetInGUIHook(this,true,false);
    	
        theplayer = null;
        (new Thread(this)).start();
    }

    public static void displayMessage(String s, int i)
    {
        msg = s;
        timeout = 85;
        color = i;
    }

    public static void displayMessage(String s)
    {
        displayMessage(s, defaultColor);
    }

    public static void checkKey(int i)
    {
        if(i == 4 && secondPress[i] && Keyboard.isKeyDown(keys[i]))
        {
            if(!theplayer.onGround && !doubleJumped)
            {
                if(!doubleJumped)
                {
                    performMove(keys[i], false, false);
                }
                doubleJumped = true;
            }
            secondPress[i] = false;
            keyTimes[i] = tickCount - 500L;
        }
        if(tickCount - keyTimes[i] < (long)minDelayTime && secondPress[i] && Keyboard.isKeyDown(keys[i]))
        {
            if(Keyboard.isKeyDown(Keyboard.getKeyIndex("SPACE")) && keyTimes[i] - keyTimes[4] - 500L < 5L && nearWall(theplayer))
            {
                performMove(keys[i], true, false);
            } else
            if(theplayer.onGround || nearWall(theplayer))
            {
                performMove(keys[i], false, false);
            } else
            if(!dodged && !doubleJumped)
            {
                performMove(keys[i], false, true);
            }
            dodged = true;
            secondPress[i] = false;
            keyTimes[i] = tickCount - 500L;
        }
        if(!Keyboard.isKeyDown(keys[i]) && !secondPress[i])
        {
            secondPress[i] = true;
        }
        if(Keyboard.isKeyDown(keys[i]) && secondPress[i])
        {
            secondPress[i] = false;
            lastKey = keys[i];
            keyTimes[i] = tickCount;
        }
    }
    
    public static boolean nearWall(Entity entity) {
		if (entity.worldObj.getCollidingBoundingBoxes(entity, entity.boundingBox.expand(0.2D, 0D, 0.2D)).size() > 0) {
			return true;
		}
		return false;
	}

    public void OnTickInGame(Minecraft minecraft)
    {
        OSDHook(minecraft, false);
    }
    
    public void OnTickInGUI(Minecraft game)
    {
      OSDHook(game, true);
    }

    public void OSDHook(Minecraft minecraft, boolean ingui)
    {
    	//displayMessage(new StringBuilder().append("ingui: ").append(ingui).toString());
    	//ingui = false;
    	
    	if (theplayer != null) {
    		//boolean hitWall = nearWall(theplayer);
    		if (/*!worldRef.multiplayerWorld && */!ingui) {
    		//if (!worldRef.multiplayerWorld) {
	        	boolean hitWall = nearWall(theplayer);
	            for(int i = 0; i < keys.length; i++)
	            {
	                checkKey(i);
	            }
	
	            if(theplayer.motionY > -1D)
	            {
	                theplayer.fallDistance = 0.0F;
	            }
	            if(theplayer.onGround)
	            {
	                doubleJumped = false;
	                dodged = false;
	            }
	            prevTimeCount = timeCount;
	            timeCount = worldRef.worldInfo.getWorldTime();
	            if(timeCount > prevTimeCount)
	            {
	                tickCount += timeCount - prevTimeCount;
	            }
    		}
        }
        if(timeout > 0 && msg != null)
        {
            ScaledResolution scaledresolution = new ScaledResolution(minecraft.gameSettings, minecraft.displayWidth, minecraft.displayHeight);
            int j = scaledresolution.getScaledWidth();
            int k = scaledresolution.getScaledHeight();
            int l = minecraft.fontRenderer.getStringWidth(msg);
            minecraft.fontRenderer.drawStringWithShadow(msg, 3, 85, 0xffffff);
            timeout--;
        }
    }

    public String Version()
    {
        return "Version 1.3.1 for MC b1.4";
    }

    public static void performMove(int i, boolean boosted, boolean inAir)
    {
        float dodgeUpForce = 0.4F;
        if(boosted)
        {
        	dodgeUpForce += 0.4F;
        }
        float jumpForce = 0.5F;
        float force = 1.6F;
        float fwForce = 0.8F;
        if(inAir)
        {
        	force = 0.8F;
        }
        if(mc.gameSettings.keyBindForward.keyCode == i)
        {
            setRelVel(theplayer, 0.0F, dodgeUpForce, 1.0F, force);
        } else
        if(mc.gameSettings.keyBindLeft.keyCode == i)
        {
            setRelVel(theplayer, -1F, dodgeUpForce, 0.0F + fwForce, force);
        } else
        if(mc.gameSettings.keyBindBack.keyCode == i)
        {
            setRelVel(theplayer, 0.0F, dodgeUpForce, -1F, force);
        } else
        if(mc.gameSettings.keyBindRight.keyCode == i)
        {
            setRelVel(theplayer, 1.0F, dodgeUpForce, 0.0F + fwForce, force);
        } else
        if(mc.gameSettings.keyBindJump.keyCode == i)
        {
            setRelVel(theplayer, 0.0F, jumpForce, 0.0F, 0.0F);
        }
    }

    public static void setRelVel(Entity entity, float f, float f1, float f2, float f3)
    {
        float f4 = 10F;
        float f5 = 0.0F;
        float f6 = entity.prevRotationYaw + (entity.rotationYaw - entity.prevRotationYaw) * f4;
        int i = (int)Math.floor((double)(f6 / 360F) + 0.5D);
        f6 = (f6 - (float)i * 360F) + 270F;
        if(f2 <= 0.0F && f2 < 0.0F)
        {
            f6 += 180F;
        }
        if(f > 0.0F)
        {
            f6 += 90F - f2 * 10F;
        } else
        if(f < 0.0F)
        {
            f6 += 270F + f2 * 10F;
        }
        float f7 = MathHelper.cos(-f6 * 0.01745329F - 3.141593F);
        float f8 = MathHelper.sin(-f6 * 0.01745329F - 3.141593F);
        float f9 = -MathHelper.cos(-f5 * 0.01745329F - 0.7853982F);
        float f10 = MathHelper.sin(-f5 * 0.01745329F - 0.7853982F);
        float f11 = f7 * f9;
        float f12 = f10;
        float f13 = f8 * f9;
        if(f == 0.0F && f2 == 0.0F)
        {
            setVel(entity, (float)entity.motionX / 2.0F, f1, (float)entity.motionZ / 2.0F);
        } else
        {
            setVel(entity, f11 * f3 * -1F, f1, f13 * f3);
        }
    }

    public static void setVel(Entity entity, float f, float f1, float f2)
    {
        entity.motionX += f;
        entity.motionY = f1;
        entity.motionZ += f2;
    }

    

}
